<template>
	<view>
		<xiaoVideoElement :src="move_info.active_url" @currentTimeVod="currentTimeVod" :initialTime="initial_time">
		</xiaoVideoElement>
		<view style="padding: 25rpx;">
			<view class="info">
				<view style="display: flex;align-items: center;">
					<text style="font-weight: 600;">{{move_info.movie_name}}</text>
				</view>
				<view style="margin-right: 20rpx;">
					<uni-icons type="star" size="60rpx" color="#f5a447" v-if="!collection" @click="storeUp"></uni-icons>
					<uni-icons type="star-filled" size="60rpx" color="#f5a447" v-else @click="UpdownstoreUp">
					</uni-icons>
				</view>
			</view>
			<!-- 简介 -->
			<view style="display: flex;align-items: center;margin: 20rpx 0;">
				<uni-icons type="wallet-filled" size="30rpx"></uni-icons>
				<text style="font-weight: 600;">影片简介</text>
			</view>
			<view style="font-size: 28rpx;color: rgba(0, 0, 0, 0.6);">
				{{move_info.active_about}}
			</view>
		</view>
	</view>
</template>
<script>
	import xiaoVideoElement from '../../components/xiao-video-component/xiao-video-component.vue'
	export default {
		components: {
			xiaoVideoElement
		},
		data() {
			return {
				move_id: "",
				move_info: "",
				initial_time: "",
				collection: ""
			}
		},
		methods: {
			test() {
				this.collection = !this.collection
			},
			// 初始化数据
			async initData() {
				let res = await uniCloud.callFunction({
					name: "move_info",
					data: {
						_id: this.move_id
					}
				})
				this.move_info = res.result.data[0]
			},
			currentTimeVod(Value) {
				// 存储在本地
				let playRecord = uni.getStorageSync("playRecord")
				if (playRecord) {
					playRecord.forEach((item, index) => {
						if (item._id == this.move_id) {
							playRecord.splice(index, 1)
						}
					})
					this.move_info.playTime = Value
					playRecord.unshift(this.move_info)
					uni.setStorageSync("playRecord", playRecord)
				} else {
					this.move_info.playTime = Value
					uni.setStorageSync("playRecord", [this.move_info])
				}
			},
			// 判断是否收藏
			Iscollection() {
				let collectionList = uni.getStorageSync("collectionList")
				if (!collectionList) return
				collectionList.forEach(item => {
					if (item._id == this.move_id) {
						this.collection = true
					}
				})
			},
			// 收藏
			storeUp() {
				let collectionList = uni.getStorageSync("collectionList")
				if (collectionList) {
					collectionList.push(this.move_info)
					uni.setStorageSync("collectionList", collectionList)
				} else {
					uni.setStorageSync("collectionList", [this.move_info])
				}
				this.collection = true

			},
			// 取消收藏
			UpdownstoreUp() {
				let collectionList = uni.getStorageSync("collectionList")
				this.collection=false
				collectionList.forEach((item, index) => {
					if (item._id == this.move_id) {
						collectionList.splice(index, 1)
					}
				})
				uni.setStorageSync("collectionList", collectionList)

			}
		},
		onLoad(option) {
			if (option.id) {
				this.move_id = option.id
				this.initData()
			}
			if (option.history) {
				let playRecord = uni.getStorageSync("playRecord")
				this.move_info = playRecord[option.history]
				this.move_id = this.move_info._id
				this.initial_time = Number(playRecord[option.history].playTime)
			}
			this.Iscollection()
		}
	}
</script>
<style scoped>
	.info {
		display: flex;
		justify-content: space-between;
	}
</style>
